package org.example.copy.DeepCopy;

public class DeepCopyExample {
    public static void main(String[] args) {
        try {
            Person originalPerson = new Person("张三", new Address("123", "成都"));
            Person deepCopiedPerson = (Person) originalPerson.clone();

            // 改变原始Person对象的Address信息
            originalPerson.getAddress().setStreet("456");

            // 输出结果，显示深拷贝后的独立性
            System.out.println("Original Person Address: " + originalPerson.getAddress().getStreet());
            System.out.println("Deep Copied Person Address: " + deepCopiedPerson.getAddress().getStreet());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
}